<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Profile_model extends Category_model {
    /* -- Call the constructor -- */

    var $tbl_name = 'member';

    function __construct() {
        parent::__construct();
    }

    function check_login($email='', $password='') {
        if ($email != '' && $password != '') {
            $this->db->where('email', $email);
            $this->db->where('password', $password);
            $query = $this->db->get($this->tbl_name);
            return $query->row_array();
        } else {
            return false;
        }
    }

    function ajax_register($arrData) {
        $this->db->insert($this->tbl_name, $arrData);
        $id = $this->db->insert_id();
        return $id;
    }    

    function insert($arrData) {
        $this->db->insert($this->tbl_name, $arrData);
        $id = $this->db->insert_id();
        return $id;
    }

    function update($id, $arrData) {
        $this->db->update($this->tbl_name, $arrData, array('id' => $id));
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete($this->tbl_name);
    }

    function view($cid = 0, $limit = 20) {
        if ($cid) {
            $this->db->where('cid', $cid);
        }
        $this->db->order_by("id", "DESC");
        $query = $this->db->get($this->tbl_name, $limit);
        return $query->result_array();
    }

    function get_total($cid = 0) {
        if ($cid) {
            $this->db->where('cid', $cid);
        }
        $query = $this->db->get($this->tbl_name);
        return $query->num_rows();
    }

}

